package com.ftg.learn.bus.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ftg.learn.bus.user.pojo.user;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface user_mapper extends BaseMapper<user> {

    @Select("select * from user where user_id=#{u.user_id} and password=#{oldPassword}")
    List<user> query(user u,String oldPassword);

    @Insert("insert into user(user_id,password,name,sex,age,contactway,createdate,updatedate) values (#{user_id},#{password},#{name},#{sex},#{age},#{contactway},CURDATE(),CURDATE())")
    int insert(user u);

    @Update("update user set password=#{password},name=#{name},sex=#{sex},age=#{age},contactway=#{contactway},updatedate=CURDATE() where user_id=#{user_id}")
    int update(user u);

    @Select("SELECT user.user_id,name,role.*,a.menu_id AS 子级菜单id,a.menu_name AS 子级菜单名称,a.menu_loc AS url,a.menu_lv AS 子级菜单等级,b.menu_id AS 父级菜单id,b.menu_name AS 父级菜单名,b.menu_lv AS 父级菜单等级 FROM user " +
            "LEFT JOIN userole_control ur ON user.user_id=ur.user_id " +
            "LEFT JOIN role ON ur.role_id=role.role_id " +
            "LEFT JOIN control_list cl ON role.role_id=cl.role_id " +
            "LEFT JOIN menu_admin a ON cl.control=a.menu_id " +
            "left JOIN menu_admin b ON a.menu_father=b.menu_id " +
            "WHERE b.menu_lv=1 AND user.user_id=#{user_id} AND user.password=#{password}")
    List<Map<String,Object>> login(String user_id ,String password);

    @Delete("<script>delete from userole_control where user_id in" +
                "<foreach collection='user_ids'  item='item' open='(' separator=',' close=')'  >" +
                    "#{item}" +
                "</foreach>" +
            "</script>")
    int deleteForUserole_control(List<String> user_ids);


}
